FROM php:7.4-cli-alpine3.15

LABEL maintainer="JasonYu <coderyu2018@gmail.com>"

# Start as root
USER root

###########################################################################
# Set Timezone
###########################################################################
ARG TZ=PRC
ENV TZ=PRC

###########################################################################
# If you're in China, or you need to change sources, will be set CHANGE_SOURCE to true in .env.
###########################################################################
ARG XEDEBUG_INSTALL=true
ARG CHANGE_SOURCE=true

RUN if [ ${CHANGE_SOURCE} = "true" ]; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; fi

RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini \
   && apk update \
   && apk add --no-cache tzdata && cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
   && apk add --no-cache libstdc++ libpq php-gd icu-dev \
   && apk add --no-cache --virtual .build-deps libzip-dev libpng-dev git $PHPIZE_DEPS curl-dev c-ares-dev \
   && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
   && php composer-setup.php && mv composer.phar /usr/bin/composer \
   ; if [ ${XEDEBUG_INSTALL} = "true" ];then pecl install xdebug  \ && docker-php-ext-enable xdebug ; fi \
   ; if [ ${CHANGE_SOURCE} = "true" ];then composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ ; fi \
  && docker-php-ext-install bcmath gd sockets pdo_mysql pcntl opcache intl\
  && pecl install redis \ && docker-php-ext-enable redis \
  && pecl install pcov \ && docker-php-ext-enable pcov \
  && apk del .build-deps \
  && rm -rf /var/cache/apk/* && rm -rf /tmp/*
# Set default work directory
WORKDIR /var/www